package com.phenix.mvp.base.mvp;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.phenix.mvp.util.TUtil;

import butterknife.ButterKnife;
import butterknife.Unbinder;


/**
 * @author  zhouphenix on 2016-7-15.
 */
public abstract class BaseActivity<P extends BaseMVPresenter> extends AppCompatActivity {
    public P mPresenter;
    Unbinder unbinder;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        unbinder = ButterKnife.bind(this);
        mPresenter = TUtil.getInstance(this,0);
        initView();
        if (this instanceof BaseView) mPresenter.setView(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (null != mPresenter) mPresenter.onDetach();
        unbinder.unbind();
    }

    public abstract int getLayoutId() ;
    public void initView(){}

}
